package com.itlaobing.response.body;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet("/download/text")
public class DownloadTextServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String path = "E:/Code/";
        String name = "TwinPrime.java";
        String pathname = path + name ;
        InputStream in = new FileInputStream( pathname);

        response.setHeader("content-type" ,"text/plain");
        response.setHeader("content-Disposition","attachment;filename="+name);

        OutputStream out = response.getOutputStream();

        in.transferTo(out);
    }
}
